#ifndef __IRR_MONITOR_H_INCLUDED__
#define __IRR_MONITOR_H_INCLUDED__

#include "IrrCompileConfig.h"

#ifdef _IRR_WINDOWS_
#include <windows.h>
#else
#include <pspkernel.h>
#endif

namespace game
{
	namespace core
	{
		class irrMonitor
		{
#ifdef _IRR_WINDOWS_
			typedef CRITICAL_SECTION LockerType;
#else
			typedef int LockerType;
#endif
			
		private:
			LockerType Locker;
		public:



			irrMonitor()
			{

#ifdef _IRR_WINDOWS_
				InitializeCriticalSection(&Locker);
#else
				Locker = sceKernelCreateSema("Locker", 0, 1, 1, 0);
#endif
			}

			~irrMonitor()
			{
#ifdef _IRR_WINDOWS_
				DeleteCriticalSection(&Locker);
#else
				sceKernelDeleteSema(Locker);
#endif
			}
			//! Acquires a lock for an object. This action also marks the beginning of a critical section. 
			//! No other thread can enter the critical section unless it is executing the instructions 
			//! in the critical section using a different locked object.
			void enter()
			{
#ifdef _IRR_WINDOWS_
				EnterCriticalSection(&Locker);
#else
				sceKernelWaitSema(Locker,1,0);
				sceKernelSignalSema(Locker,0);
#endif
			}
			//! Releases the lock on an object in order to permit other threads to lock and access the object. 
			//! The calling thread waits while another thread accesses the object. 
			//! Pulse signals are used to notify waiting threads about changes to an object's state.
			/*void wait()
			{

			}*/

			//! Releases the lock on an object. This action also marks the end of a critical section protected by the locked object.
			void exit()
			{
#ifdef _IRR_WINDOWS_
				LeaveCriticalSection(&Locker);
#else
				sceKernelSignalSema(Locker,1);
#endif
			}
		};
	}


}

#endif